using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using SkypeStudio.Controls.ViewModels;
using SkypeStudio.Controls.Views;
using SkypeStudio.Controls.Test.ViewMock;
using SkypeStudio.Controls.Services;
using Rhino.Mocks.Interfaces;
using System.Threading;

namespace SkypeStudio.Controls.Test.ViewModel
{
    [TestClass]
    public class ContactListViewModelTest : BaseTest
    {
        [TestMethod]
        public void SkypeEventListeningTest()
        {
            ISkypeApplicationService skypeService = _Mock.StrictMock<ISkypeApplicationService>();
            IContactListView view = new MockContactListView();
            IEventRaiser skypeProcessAttachStatusChanged = null;

            using (_Mock.Record())
            {
                skypeProcessAttachStatusChanged = Expect.Call(delegate { skypeService.SkypeProcessAttachStatusChanged += null; }).IgnoreArguments().GetEventRaiser();
            }

            using (_Mock.Playback())
            {
                ContactListViewModel target = new ContactListViewModel(view, skypeService);
                List<string> propertyChangeLsit = new List<string>();
                target.PropertyChanged += (s, e) => { propertyChangeLsit.Add(e.PropertyName); };
                skypeProcessAttachStatusChanged.Raise(SkypeProcessAttachStatus.apiAttachSuccess);

                Assert.AreEqual(3, propertyChangeLsit.Count);
                Assert.IsTrue(propertyChangeLsit.Any(o => o == "ContactList"));
                Assert.IsTrue(propertyChangeLsit.Any(o => o == "IsSkypeProcessAttachedReady"));
                Assert.IsTrue(propertyChangeLsit.Any(o => o == "IsNoySkypeProcessAttachedReady"));
            }
        }
    }
}
